package stack;

import array.CandyArray;

public class CandyArrayStack<E> implements CandyStack<E> {
	private CandyArray<E> candyArray;
	
	public CandyArrayStack() {
		candyArray = new CandyArray<>();
	}

	public CandyArrayStack(int capacity) {
		candyArray = new CandyArray<>(capacity);
	}

	@Override
	public int getSize() {
		return candyArray.getSize();
	}

	@Override
	public boolean isEmpty() {
		return candyArray.isEmpty();
	}

	@Override
	public void push(E e) {
		candyArray.addLast(e);
	}

	@Override
	public E pop() {
		return candyArray.removeLast();
	}

	@Override
	public E peak() {
		return candyArray.getLast();
	}
	
	
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder("CandyArrayStack: [");
		for(int i = 0; ; i++) {
			sb.append(candyArray.get(i));
			if(i == candyArray.getSize() - 1)
				return sb.append("] top").toString();
			sb.append(", ");
		}
	}

	public static void main(String[] args) {
		CandyArrayStack<Integer> stack = new CandyArrayStack<>(); 
		for(int i = 0; i < 5; i++) {
			stack.push(i);
			System.out.println(stack);
		}
		System.out.println("出栈元素：" + stack.pop());
		System.out.println(stack);
	}
}
